package com.wxh.controller;


import com.wxh.domain.Airports;
import com.wxh.domain.Flights;
import com.wxh.service.AirportsService;
import com.wxh.service.FlightsService;
import com.wxh.utils.Result;
import com.wxh.vo.FilghtsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2020-04-15
 */
@RestController
@RequestMapping(value = "flights")
public class FlightsController {
    @Autowired
    private FlightsService flightsService;
    @Autowired
    private AirportsService airportsService;

    @RequestMapping(value = "query",method = RequestMethod.POST)

    public Result query(@RequestBody FilghtsVo filghtsVo) {
        System.out.println(filghtsVo);
        List<Flights> list = this.flightsService.list();
        for (Flights f : list) {
            Airports id1 = this.airportsService.getById(f.getLandingAirportId()); //Jiangluo
            Airports id2 = this.airportsService.getById(f.getTakeoffAirportId());//qifei
            f.setStart(id2.getAirportName()).setEnd(id1.getAirportName());
        }
        return new Result(200, list);
    }
}

